// 导入数据库API
const db = require("../../config/db");

module.exports = {
    add_like(user_id, like_gid) {
        return new Promise((resolve, reject) => {
            let add_like_sql = `insert into db_like(user_id,like_gid) values("${user_id}","${like_gid}")`;
            db.query(add_like_sql, (err, rows) => {
                if (err) {
                    reject(err);
                } else {
                    resolve();
                }
            });
        });
    },

    remove_like(user_id, like_gid) {
        return new Promise((resolve, reject) => {
            let remove_like_sql = `DELETE FROM db_like WHERE user_id="${user_id}" and like_gid="${like_gid}"`;
            db.query(remove_like_sql, (err, rows) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(rows);
                }
            });
        });
    },

    get_like() {
        return new Promise((resolve, reject) => {
            let get_like_sql = `select * from db_like`;
            db.query(get_like_sql, (err, rows) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(rows);
                }
            });
        });
    },

    get_like_list(gids) {
        return new Promise((resolve, reject) => {
            let get_like_list_sql = `select * from db_goods where FIND_IN_SET(gid,'${gids}')`;
            db.query(get_like_list_sql, (err, rows) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(rows);
                }
            });
        });
    },
};
